/****************************************************
          File Name:8-4.cpp
          Author: Abby Cin
          Mail: abbytsing@gmail.com
          Created Time: Sat 20 Dec 2014 07:34:01 PM CST
*****************************************************/

#include<iostream>
#include<cstring>
using namespace std;

struct stringy
{
    char *str;
    int ct;
};

void set(stringy & arg1, const char *arg2)  // no delete in the scope
{
    char *backup = new char[strlen(arg2)];
    strcpy(backup, arg2);
    arg1.str = backup;
    arg1.ct = strlen(arg2);
}

void show(const char *arg1, int n = 0)
{
    cout << "In show char * ------\n" << endl;
    if(n != 0)
    {
        while(n--)
            cout << arg1 << endl;
    }
    else
    {
        cout << arg1 << endl;
    }
}

void show(const stringy & arg1, int n = 0)     // overload
{
    cout << "In show struct ----\n" << endl;
    if(n != 0)
    {
        while(n--)
        {
            cout << arg1.str << endl;
            cout << arg1.ct << endl;
        }
    }
    else
    {
        cout << arg1.str << endl;
        cout << arg1.ct << endl;
    }
}

int main()
{
    stringy beany;
    char testing[] = "Reality isn't what it used to be.";

    set(beany, testing);

    show(beany);
    show(beany, 2);
    testing[0] = 'D';
    testing[1] = 'u';
    show(testing);
    show(testing, 3);
    show("Done!");

    return 0;
}
